package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.dao.User;
import com.example.demo.service.UserService;
import com.example.demo.service.impl.UserServiceImpl;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@CrossOrigin
public class UserController {


    private final UserServiceImpl userService;

    public UserController(UserServiceImpl userService) {
        this.userService = userService;
    }

    /**
     * 新增高管信息
     *
     * @param user 高管信息
     * @return 是否成功
     */
    @RequestMapping("/user/add")
    public String addUserInfo(User user) {

        User username = userService.findUsername(user.getUsername());
        if (null != username) {
            return "error";
        }else {
            Boolean addJudge = userService.addUserInfo(user);
            if (addJudge) {
                return "success";
            } else {
                return "error";
            }
        }

    }

    @RequestMapping("/user/login/{user}")
    public String userLogin(@PathVariable User user){
        System.out.println(user);
        User serviceUser = userService.findUser(user.getUsername(), user.getPassword());
        System.out.println(serviceUser);
        if(null != serviceUser){
            return "true";
        } else{
            return "error";
        }
    }
}

